Skip to content

Add rule for Link to not be allowed without href #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2025
Merged

Conversation

pksjce
Copy link
Contributor

@pksjce pksjce commented Jul 8, 2025

If a Link component from @primer/react is used without an href attribute, it is now flagged as an error.
"Links without href and other side effects are not accessible. Use a Button instead."

@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 03:38
@pksjce pksjce requested a review from a team as a code owner July 8, 2025 03:38
@pksjce pksjce requested a review from hectahertz July 8, 2025 03:38
Copy link

changeset-bot bot commented Jul 8, 2025

🦋 Changeset detected

Latest commit: 024794c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-primer-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new ESLint rule to enforce accessibility best practices by preventing the use of Link components from @primer/react without an href attribute. The rule suggests using a Button component instead for interactive elements that don't navigate to a URL.

  • Implements new rule enforce-button-for-link-with-nohref to detect Link components without href attributes
  • Provides comprehensive test coverage for valid and invalid usage scenarios
  • Includes proper error messaging and rule metadata configuration

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/rules/enforce-button-for-link-with-nohref.js Main rule implementation that checks for Link components without href attributes
src/rules/tests/enforce-button-for-link-with-nohref.test.js Test suite covering valid and invalid usage scenarios

url: url(module),
},
messages: {
noLinkWithoutHref:

This comment was marked as resolved.

noLinkWithoutHref:
'Links without href and other side effects are not accessible. Use a Button instead.',
},
fixable: 'code',
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule is marked as fixable but no fix function is implemented. Either implement the fix logic or remove the 'fixable' property.

Copilot uses AI. Check for mistakes.

@pksjce pksjce requested a review from francinelucca July 8, 2025 03:49
@pksjce pksjce merged commit ec701d2 into main Jul 9, 2025
9 checks passed
@pksjce pksjce deleted the pk/link-ref branch July 9, 2025 21:24
@primer-css primer-css mentioned this pull request Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants